local skel = fk.CreateSkill {
  name = "emo__zhisi",
}

Fk:loadTranslationTable{
  ["emo__zhisi"] = "智思",
  [":emo__zhisi"] = "每当你受到伤害后，你可以摸手牌中已有或未有的花色各一张牌。",

  ["emo__zhisi_have"] = "摸<font color='pink'>已有</font>花色",
  ["emo__zhisi_nohave"] = "摸<font color='red'>未有</font>花色",
}

skel:addEffect(fk.Damaged, {
  anim_type = "drawcard",
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(skel.name)
  end,
  on_cost = function (self, event, target, player, data)
    local all_choices = {"emo__zhisi_have", "emo__zhisi_nohave", "Cancel"}
    local choices = {"Cancel"}
    local nohave, have = {"spade", "heart", "diamond", "club"}, {}
    for _, id in ipairs(player:getCardIds("h")) do
      local suit = Fk:getCardById(id):getSuitString()
      if table.removeOne(nohave, suit) then
        table.insert(have, suit)
      end
    end
    if #nohave > 0 then
      table.insert(choices, 1, "emo__zhisi_nohave")
    end
    if #have > 0 then
      table.insert(choices, 1, "emo__zhisi_have")
    end
    local choice = player.room:askToChoice(player, {skill_name = skel.name, choices = choices, all_choices = all_choices })
    if choice ~= "cancel" then
      event:setCostData(self, choice == "emo__zhisi_have" and have or nohave)
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local suits = event:getCostData(self)
    local get = {}
    for _, suit in ipairs(suits) do
      local ids = room:getCardsFromPileByRule(".|.|"..suit)
      if #ids > 0 then table.insert(get, ids[1]) end
    end
    room:obtainCard(player, get, false, fk.ReasonPrey, player, skel.name)
  end,
})

return skel
